package com.opdar.athena.message.agent.client;

import com.opdar.athena.base.RedisSessionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by shiju on 2017/7/2.
 */
public class ClientPool {
    public Map<String, Client> clients = new HashMap<String, Client>();
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    RedisSessionManager redisSessionManager;

    public Client getClient(InetSocketAddress address) {
        return clients.get(address.getAddress().getHostAddress() + ":" + address.getPort());
    }
    public Client getClient(String address) {
        return clients.get(address);
    }
    public Client putClient(InetSocketAddress address,Client client) {
        return clients.put(address.getAddress().getHostAddress() + ":" + address.getPort(),client);
    }

    public Client removeClient(InetSocketAddress address) {
        return clients.remove(address.getAddress().getHostAddress() + ":" + address.getPort());
    }
    public boolean contains(InetSocketAddress address) {
        return clients.containsKey(address.getAddress().getHostAddress() + ":" + address.getPort());
    }
}
